using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Linq;
using DevExpress.XtraReports.UI;
using System.Collections.Generic;

namespace QLTV.Reports
{
    public partial class rptThayThuyenVien : DevExpress.XtraReports.UI.XtraReport
    {
        public rptThayThuyenVien()
        {
            InitializeComponent();

        }
        int _stt = 0;
        private void xrLabel18_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            _stt++;
            xrLabel18.Text = "(" + _stt + ")";
        }
        Database.dsVessel.tblVesselDataTable dtVessel;
        public void loadData(int planId, int vesselId, List<string> listNextCrew, List<string> listOffCrew)
        {

            //Today
            txtToDay.Text = DateTime.Now.Date.ToString("dd-MMM-yyyy");

            //get vesselDetail
            using (Database.dsVesselTableAdapters.tblVesselTableAdapter tadVessel = new Database.dsVesselTableAdapters.tblVesselTableAdapter())
            {
                dtVessel = new Database.dsVessel.tblVesselDataTable();
                tadVessel.FillbyID(dtVessel, vesselId);
                txtTenTau.Text = dtVessel.Rows[0]["cVesselName"].ToString();
                txtTenTau2.Text = dtVessel.Rows[0]["cVesselName"].ToString();
            }
            //get plan detail
            using (Database.dsReportTableAdapters.tblKeHoachTableAdapter tadKeHoach = new Database.dsReportTableAdapters.tblKeHoachTableAdapter())
            {
                tadKeHoach.FillBy(dsReport2.tblKeHoach, planId);
                txtDate.Text = ((DateTime)dsReport2.tblKeHoach.Rows[0]["NgayDuKienThucHien"]).ToString("dd-MM-yyyy");
            }
            //Get signer Crew
            tblCrewTableAdapter1.Fill(dsReport2.tblCrew);


            //signer crews
            IList signerCrewList = (from c in dsReport2.tblCrew.AsQueryable()
                                    where listNextCrew.Contains(c.nCrewId)
                                    select new
                                    {
                                        nCrewId = c.nCrewId,
                                        cRankName = c.cRankName,
                                        FullName = c.FullName,
                                        dDateOfBirth = (c.IsdDateOfBirthNull() ? null : c.dDateOfBirth.ToString("dd/MM/yyyy")),
                                        cPlaceOfBirth = (c.IscPlaceOfBirthNull() ? null : c.cPlaceOfBirth),
                                        fShoeSize = (c.IsfShoeSizeJPNull() ? 0 : c.fShoeSizeJP)
                                    }).ToList();

            this.DataSource = signerCrewList;

            this.txtRank.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "cRankName")});
            this.txtFullName.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "FullName")});
            this.txtDOB.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "dDateOfBirth")});
            this.txtPOB.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "cPlaceOfBirth")});
            this.txtShoeSize.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "fShoeSize)")});
            //load off
            ((rptOffSigner)subOff.ReportSource).loadData(listOffCrew);
        }

        private void ThuyenVIen_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            //this.Parameters[0].Value = this.GetCurrentColumnValue("nCrewId");
            tblEducationTableAdapter1.FillByCrewID(dsReport2.tblEducation, this.GetCurrentColumnValue("nCrewId").ToString());
            tblExprienceTableAdapter1.Fill(dsReport2.tblExprience, this.GetCurrentColumnValue("nCrewId").ToString());
            tblImmigrationCrewTableAdapter1.FillByCrewID(dsReport2.tblImmigrationCrew, this.GetCurrentColumnValue("nCrewId").ToString());
        }


        private void txtFullName_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            txtFullName.Text = Ultilities.RemoveSign4VietnameseString(txtFullName.Text);
        }

        private void txtPOB_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            txtPOB.Text = Ultilities.RemoveSign4VietnameseString(txtPOB.Text);
        }


        //education
        private void Detail5_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            if (dsReport2.tblEducation.Rows.Count > 0)
            {

                string tentienganh = "";
                if (detail_Education.GetCurrentColumnValue("TenTiengAnh") != null)
                {
                    tentienganh = detail_Education.GetCurrentColumnValue("TenTiengAnh").ToString().ToUpper() + ", ";
                }
                string period = "";
                if (detail_Education.GetCurrentColumnValue("dPeriod") != null)
                {
                    period = detail_Education.GetCurrentColumnValue("dPeriod").ToString().ToUpper() + " YEAR COURSE, ";
                }
                string course = "";
                if (detail_Education.GetCurrentColumnValue("cCourseName") != null)
                {
                    course = detail_Education.GetCurrentColumnValue("cCourseName").ToString().ToUpper() + ", ";
                }
                string finish = "";
                if (detail_Education.GetCurrentColumnValue("cFinishYear") != null)
                {
                    finish = detail_Education.GetCurrentColumnValue("cFinishYear").ToString().ToUpper();
                }
                txtEdu.Text = tentienganh + period + course + finish;
            }
        }
        //exp
        private void Detail6_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            if (dsReport2.tblExprience.Rows.Count > 0)
            {
                string rank = "";
                if (detailExp.GetCurrentColumnValue("cRankName")!=DBNull.Value)
                {
                    rank = detailExp.GetCurrentColumnValue("cRankName").ToString().ToUpper() + "/";
                }
                string shipName = "";
                if (detailExp.GetCurrentColumnValue("cVesselName") != DBNull.Value)
                {
                    shipName = detailExp.GetCurrentColumnValue("cVesselName").ToString().ToUpper() + "/";
                }
                string flag = "";
                if (detailExp.GetCurrentColumnValue("cFlagCountry") != DBNull.Value)
                    flag = detailExp.GetCurrentColumnValue("cFlagCountry").ToString().ToUpper() + "/";
                string type = "";
                if (detailExp.GetCurrentColumnValue("cVesselType") != DBNull.Value)
                    type = detailExp.GetCurrentColumnValue("cVesselType").ToString().ToUpper() + "/";

                string embark = "";
                if (detailExp.GetCurrentColumnValue("dEmbarkedDate") != DBNull.Value)
                    embark = ((DateTime)detailExp.GetCurrentColumnValue("dEmbarkedDate")).ToString("dd.MMM.yyyy") + "/";
                string disembark = "";
                if (detailExp.GetCurrentColumnValue("dDisembarkedDate") != DBNull.Value)
                    disembark = ((DateTime)detailExp.GetCurrentColumnValue("dDisembarkedDate")).ToString("dd.MMM.yyyy");
                txtKinhNghiem.Text = rank + shipName + flag + type + embark + disembark;
            }

        }
    }
}
